home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (C) 1991 Aladdin Enterprises. All rights reserved.
- Distributed by Free Software Foundation, Inc.
-
- This file is part of Ghostscript.
-
- Ghostscript is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
- to anyone for the consequences of using it or for whether it serves any
- particular purpose or works at all, unless he says so in writing. Refer
- to the Ghostscript General Public License for full details.
-
- Everyone is granted permission to copy, modify and redistribute
- Ghostscript, but only under the conditions described in the Ghostscript
- General Public License. A copy of this license is supposed to have been
- given to you along with Ghostscript so you can know your rights and
- responsibilities. It should be in a file named COPYING. Among other
- things, the copyright notice and this notice must be preserved on all
- copies. */
-
- /* gdevvdi.c */
-
- /* Bitmapped screen device for the Atari ST. This driver contains
- * portions of code originally written by Hauke Hess. It uses the
- * vdi for all screen operations. It recognizes and supports 1, 2,
- * 4, 8, and 16 bit color. Tim Gallivan 9/93.
- */
-
- /* For monochrome, Ghostscript produces a bitmap in memory which
- * is referenced directly by 'base'. For color images, GS produces
- * a bitmap at 'base' with each pixel represented by several
- * consecutive bits (packed or chunky pixel format). The routine
- * 'pack_to_plane()' copies the GS "packed" image format into the
- * appropriate number of color planes, referenced by 'cbase'. The
- * image in 'cbase' is then copied back to 'base' with the vdi routine
- * 'vr_trnfm()', and is then copied to the screen. This is rather
- * convoluted, but is needed for portability.
- */
-
- #include "gdevvdi.h"
-
- /* Variables imported from gp_atari.c */
-
- extern gx_color_value MaxRGB;
- extern short Chunky8, Chunky16;
- extern short Gdebug, Debug8, Debug16;
- extern short TrueColor;
- extern int *Palette;
- extern uint PaletteSize;
- extern int *ColorReg;
- extern int XRes, YRes, ColorBits;
- extern int msgbuff[], pxy[];
- extern int VdiHandle;
- extern int window;
- extern float AspectRatio;
-
- extern WINDOW imag;
- extern GRECT full;
- extern MFDB plane_image, image, screen;
-
- /* General screen driver variables. */
-
- /* lineptr is an array of pointers to the beginning of each scan
- * line in the GS bitmap.
- */
-
- byte *cbase=0, **lineptr;
- ushort *plane[16], *tbase;
-
- uint csize;
-
- int ColorIndex=2, words;
-
- int width, height, byte_width, word_width, raster;
- int plot_x, plot_y, step_dx, step_dy;
- int copy_width, copy_height;
-
- /* Global Ghostscript variables. */
-
- ulong mem_space;
-
- private dev_proc_open_device(stvdi_open);
- private dev_proc_close_device(stvdi_close);
- private dev_proc_output_page(stvdi_output_page);
- private dev_proc_print_page(stvdi_print_page);
- private dev_proc_map_rgb_color(stvdi_map_rgb_color);
- private dev_proc_map_color_rgb(stvdi_map_color_rgb);
-
- private gx_device_procs stvdi_procs =
- prn_color_procs(stvdi_open, stvdi_output_page, stvdi_close,
- stvdi_map_rgb_color, stvdi_map_color_rgb);
-
- gx_device_printer gs_stvdi_device =
- prn_device(stvdi_procs, "stvdi",
- WIDTH_10THS, HEIGHT_10THS,
- X_DPI, Y_DPI,
- 0,0,0,0, /* margins */
- 1, stvdi_print_page); /* default to monochrome */
-
- /* Open the stvdi device--get the resolution, allocate memory, etc. */
-
- int
- stvdi_open(gx_device *pdev)
- {
- byte *base=0;
- const gx_device_memory *mdev;
- gx_device_procs *pprocs = pdev->procs;
-
- int ret;
-
- if (Gdebug) eprintf("stvdi_open ...");
-
- pdev->y_pixels_per_inch =
- (int)(AspectRatio * pdev->y_pixels_per_inch + .5);
- pdev->height = (int)(AspectRatio * pdev->height + .5);
-
- /* Get an appropriate memory device. */
-
- if ((mdev = gdev_mem_device_for_bits(ColorBits)) == 0)
- return_error(gs_error_rangecheck);
-
- width = pmemdev->width; /* width in pixels */
- height = pmemdev->height; /* height in pixels */
-
- byte_width = (width + 7) >> 3; /* pixel width / 8 */
- word_width = (byte_width + 1) >> 1; /* pixel width / 16 */
-
- /* Ensure that the width is a multiple of 16 pixels. */
-
- pmemdev->width = 16 * word_width;
-
- if (window) {
-
- wind_calc(0, imag.gadgets,
- imag.canvas.g_x, imag.canvas.g_y, width, height,
- &imag.mframe.g_x, &imag.mframe.g_y,
- &imag.mframe.g_w, &imag.mframe.g_h);
-
- imag.oframe.g_x = 0; imag.oframe.g_y = 0;
- imag.oframe.g_w = 0; imag.oframe.g_h = 0;
-
- }
-
- if (ColorBits > 1) {
-
- /* Fill the color_info structure. */
-
- ppdev->color_info.num_components = 3;
- ppdev->color_info.depth = mdev->color_info.depth;
- ppdev->color_info.max_gray = PaletteSize/3 - 1;
- ppdev->color_info.max_rgb = MaxRGB;
- ppdev->color_info.dither_gray = DITH_GRAY(ColorBits);
- ppdev->color_info.dither_rgb = DITH_RGB(ColorBits);
-
- if (Gdebug) {
- eprintf1("Depth = %ld\n", ppdev->color_info.depth);
- eprintf1("Max Gray = %ld\n", ppdev->color_info.max_gray);
- eprintf1("Max RGB = %ld\n", ppdev->color_info.max_rgb);
- eprintf1("Dither Gray = %ld\n", ppdev->color_info.dither_gray);
- eprintf1("Dither RGB = %ld\n", ppdev->color_info.dither_rgb);
- }
-
- }
-
- memset(ppdev->skip, 0, sizeof(ppdev->skip));
- ppdev->orig_procs = pprocs;
- ppdev->page_count = 0;
- ppdev->file = ppdev->ccfile = ppdev->cbfile = NULL;
- mem_space = gdev_mem_bitmap_size(pmemdev);
-
- /* Base points to a buffer that GS uses to construct the image. */
-
- if ( mem_space != (uint)mem_space || /* too big to allocate */
- (base = (byte *)gs_malloc((uint)mem_space, 1, "printer buffer"))
- == 0 /* can't allocate */
- ) {
- eprintf("stvdi_open: Malloc for printer buffer failed.\n");
- return_error(gs_error_VMerror);
- }
-
- /* Cbase points to a buffer that holds the standard GEM
- * color plane image.
- */
-
- if ((ColorBits > 1) && !Chunky8 && !Chunky16) {
-
- csize = (uint)(2 * word_width * height * ColorBits);
-
- if ((cbase = (byte *)gs_malloc(csize, 1, "color buffer")) == 0) {
- eprintf("stvdi_open: Malloc for color buffer failed.\n");
- return_error(gs_error_VMerror);
- }
-
- }
-
- /* Render entirely in memory. */
-
- ppdev->buffer_space = 0;
- pmemdev->base = base;
- ppdev->mod_procs = *mdev->procs;
-
- /* Synthesize the procedure vector. */
- /* Rendering operations come from the memory device, */
- /* non-rendering come from the printer device. */
-
- pdev->procs = &ppdev->mod_procs;
-
- #define copy_proc(p) ppdev->mod_procs.p = pprocs->p
- copy_proc(get_initial_matrix);
- copy_proc(output_page);
- copy_proc(close_device);
- copy_proc(map_rgb_color);
- copy_proc(map_color_rgb);
- copy_proc(get_props);
- copy_proc(put_props);
- copy_proc(map_cmyk_color);
- copy_proc(get_xfont_procs);
- copy_proc(get_xfont_device);
- #undef copy_proc
-
- /* Open the memory device. */
-
- if ((ret = (*pdev->procs->open_device)(pdev)) != 0) {
- return ret;
- }
-
- raster = pmemdev->raster;
-
- /* Set up the MFDBs for the GS image and the screen. */
-
- screen.fd_addr = (long)NULL;
-
- image.fd_addr = (long)base;
- image.fd_w = (ColorBits > 1) ? 16 * word_width: 8 * raster;
- image.fd_h = height;
- image.fd_wdwidth = image.fd_w/16;
- image.fd_stand = 0;
- image.fd_nplanes = ColorBits;
-
- if (ColorBits > 1 && cbase) {
-
- /* Set up the MFDB for the color image buffer. */
-
- plane_image.fd_addr = (long)cbase;
- plane_image.fd_w = 16 * word_width;
- plane_image.fd_h = height;
- plane_image.fd_wdwidth = image.fd_w/16;
- plane_image.fd_stand = 1;
- plane_image.fd_nplanes = ColorBits;
-
- }
-
- return 0;
- }
-
- /* Close the stvdi device--free memory, close workstations, etc. */
-
- int
- stvdi_close(gx_device *pdev)
- {
-
- if (Gdebug) eprintf("stvdi_close ...");
-
- /* Close the window. */
-
- if (imag.opened) {
- if (Gdebug) eprintf("closing win in stvdi close");
- wind_close(imag.handle);
- imag.opened = 0;
- }
-
- /* Free the memory device bitmap. */
-
- gs_free((char *)pmemdev->base, (uint)gdev_mem_bitmap_size(pmemdev),
- 1, "printer buffer");
-
- /* Free the memory for the color image buffer. */
-
- if (ColorBits > 1 && cbase) {
- gs_free((char *)cbase, csize, 1, "color buffer");
- }
-
- pdev->procs = ppdev->orig_procs;
-
- return 0;
- }
-
- int
- stvdi_output_page(gx_device *pdev, int num_copies, int flush)
- { int code;
-
- ppdev->page_count++;
-
- /* print the accumulated page description */
- code = (*ppdev->print_page)(ppdev, ppdev->file);
-
- ColorIndex = 2; /* indices > 2 available for new colors. */
-
- if ( code < 0 ) return code;
- return 0;
- }
-
- /* Print the bitmap for the current page to the screen. */
-
- private int
- stvdi_print_page(gx_device_printer *pdev, FILE *dummy)
- {
- byte *base;
-
- int count, show_end, pad, length, top, empty;
-
- long ch;
-
- show_end = 0;
-
- /* Calculate the number of padding bits in the last byte. */
-
- pad = (8 * byte_width - width) * ColorBits;
- length = byte_width * ColorBits;
-
- plot_x = 0;
- plot_y = 0;
-
- lineptr = pmemdev->line_ptrs;
- base = *lineptr;
- tbase = (ushort *)base; /* accessed from assembly routines */
-
- /* Find the first line containing nonzero bits. */
-
- while (plot_y < height) {
-
- /* Search the scanline for a nonzero bit. */
-
- for (count=0; (count < length)
- && (base[count] == 0); ++count) ;
-
- if (count >= length) { /* Empty line, continue. */
- plot_y++;
- base = lineptr[plot_y];
- }
- else if ((count==length-1) && (base[count]>>pad == 0)) {
- plot_y++; /* nonzero bits in padding, continue */
- base = lineptr[plot_y];
- }
- else { /* Nonzero bits found, break loop. */
- plot_y--;
- break;
- }
- }
-
- /* Convert the packed image to standard GEM color planes,
- * then convert the plane image to the final platform-dependent
- * screen format. If the platform-dependent format is chunky,
- * then do nothing.
- */
-
- if (ColorBits == 16 && Chunky16) {
- ;
- }
- else if (ColorBits == 8 && Chunky8) {
- ;
- }
- else {
- stvdi_pack_to_plane();
- vr_trnfm(VdiHandle, &plane_image, &image);
- }
-
- /* Open a window if necessary. */
-
- if (window) {
-
- graf_mouse(M_OFF, 0L );
-
- if (imag.oframe.g_w && imag.oframe.g_w) {
-
- if (imag.opened) {
-
- msgbuff[3] = imag.handle;
- gp_win_redraw(FULL_WIN);
-
- #if 0
- wind_get(0, WF_TOP, &top, &empty,
- &empty, &empty);
-
- if (top == imag.handle) {
- msgbuff[3] = imag.handle;
- gp_win_redraw(FULL_WIN);
- }
- else {
- wind_set(imag.handle, WF_TOP, 0, 0, 0, 0);
- }
- #endif
-
- }
- else {
-
- wind_open(imag.handle,
- imag.oframe.g_x, imag.oframe.g_y,
- MIN(imag.mframe.g_w, imag.oframe.g_w),
- MIN(imag.mframe.g_h, imag.oframe.g_h));
-
- }
-
- }
- else if (!imag.opened) {
-
- wind_open(imag.handle,
- full.g_x, full.g_y,
- MIN(imag.mframe.g_w, full.g_w),
- MIN(imag.mframe.g_h, full.g_h));
-
- wind_get(imag.handle, WF_CURRXYWH,
- &imag.oframe.g_x, &imag.oframe.g_y,
- &imag.oframe.g_w, &imag.oframe.g_h);
-
- wind_get(imag.handle, WF_WORKXYWH,
- &imag.canvas.g_x, &imag.canvas.g_y,
- &imag.canvas.g_w, &imag.canvas.g_h);
-
- }
-
- update_scroll(imag.handle);
- imag.opened = 1;
-
- graf_mouse(BUSY_BEE, 0L);
- graf_mouse(M_ON, 0L);
-
- }
- else {
-
- copy_width = MIN(XRes, width-1); /* in pixels */
- copy_height = MIN(YRes, height-1); /* in pixels */
- step_dx = .9 * copy_width;
- step_dy = .9 * copy_height;
-
- if (plot_y < 0)
- plot_y = 0;
-
- if (plot_y >= height - copy_height)
- plot_y = (height - 1) - copy_height;
-
- v_exit_cur(VdiHandle);
-
- }
-
- if (Debug8 || Debug16) {
- dprintf1("%s\n", "Done!");
- getchar();
- return 0;
- }
-
- while (!show_end && !window) {
-
- pxy[0] = plot_x;
- pxy[1] = plot_y;
- pxy[2] = pxy[0] + copy_width;
- pxy[3] = pxy[1] + copy_height;
- pxy[4] = 0;
- pxy[5] = 0;
- pxy[6] = pxy[4] + copy_width;
- pxy[7] = pxy[5] + copy_height;
-
- graf_mouse(M_OFF, 0L );
- vs_clip(VdiHandle, 1, &pxy[4]);
- wind_update(BEG_UPDATE); /* lock the screen */
-
- vro_cpyfm(VdiHandle, 3, pxy, &image, &screen);
-
- wind_update(END_UPDATE); /* release screen */
- vs_clip(VdiHandle, 0, &pxy[4]);
- graf_mouse(ARROW, 0L );
- graf_mouse(M_ON, 0L );
-
- /* Accept keyboard commands to manipulate the screen image. */
-
- ch = (Bconin(2) >> 16) & 255; /* Get key scancode */
-
- switch(ch) {
-
- case 16: /* Q */
- show_end = 1;
- break;
-
- case 71: /* Clr/Home */
- step_dx /= 2; step_dy /= 2;
- if (step_dx < 2) step_dx = 1;
- if (step_dy < 2) step_dy = 1;
- break;
-
- case 72: /* Up cursor */
- plot_y = MAX(plot_y - step_dy, 0);
- break;
-
- case 75: /* Left cursor */
- plot_x = MAX(plot_x - step_dx, 0);
- break;
-
- case 77: /* Right cursor */
- plot_x = plot_x + step_dx;
- if (plot_x >= width - copy_width)
- plot_x = (width - 1) - copy_width;
- if (plot_x < 0) plot_x = 0;
- break;
-
- case 80: /* Down cursor */
- plot_y = plot_y + step_dy;
- if (plot_y >= height - copy_height)
- plot_y = (height - 1) - copy_height;
- if (plot_y < 0) plot_y = 0;
- break;
-
- case 82: /* Insert */
- step_dx *= 2; step_dy *= 2;
- if (step_dx > copy_width) step_dx = copy_width;
- if (step_dy > copy_height) step_dy = copy_height;
- break;
-
- case 97: /* Undo */
- plot_x = 0;
- plot_y = 0;
- break;
-
- case 98: /* Help */
- stvdi_DisplayHelp();
- Bconin(2);
- stvdi_clear_screen(0);
- break;
-
- }
-
- }
-
- if (!window) {
- v_enter_cur(VdiHandle);
- }
-
- return (0);
-
- }
-
- int stvdi_DisplayHelp()
- {
- dprintf2("%c%c Help for GhostScript Screen Driver\n", 27, 'E');
- dprintf(" Original Code by Hauke Hess.\n\n");
- dprintf(" Q: Quit this page (to next page or GS prompt).\n");
- dprintf(" Cursor Keys: Scroll screen in direction of cursor.\n");
- dprintf(" Help: Display help screen.\n");
- dprintf(" Undo: Move to upper-left corner of page.\n");
- dprintf(" Insert: Multiply scroll incrememt by 2.\n");
- dprintf(" Clr/Home: Divide scroll increment by 2.\n");
- dprintf("\n Command line option -r<XDPI>x<YDPI> sets resolution.\n");
-
- #if 0
- dprintf("\n Helpseite des GhostScript Previewers no(c)\n");
- dprintf(" Hauke Heß 1991\n");
- dprintf(" Cursortasten: bewegen in entsprechender Richtung\n");
- dprintf(" Undo: Zurück nach links oben auf der Seite\n");
- dprintf(" Insert: Schrittweiter vergrößern\n");
- dprintf(" Clr/Home: Schrittweite verkleinern\n");
- dprintf("\n Kommandozeilenparameter -r<XDPI>x<YDPI> setzt die Auflösung\n");
- #endif
-
- dprintf("\n >> Hit any key to continue. <<");
-
- return(0);
- }
-
- int
- stvdi_clear_screen(int cursor)
- {
- if (cursor) {
- v_enter_cur(VdiHandle);
- }
- else {
- v_exit_cur(VdiHandle);
- }
- }
-
-
- /* Map a r-g-b color to a color index. */
-
- /* Ghostscript asks this routine which color index should be associated
- * with a given RGB triplet. I try to make the most of a limited number
- * of colors by setting the palette dynamically as GS requests colors.
- * Black and white, however, always reside at color indices 1 and 0.
- * When the palette is full and a new color is requested, the closest
- * color in the palette is returned.
- */
-
- #define BK 0
- #define WT 3000
-
- gx_color_index
- stvdi_map_rgb_color(gx_device *pdev, gx_color_value r, gx_color_value g,
- gx_color_value b) {
-
- register int *pptr = Palette;
- register int diff;
-
- int *pptr2 = Palette;
- static int BlackSet=0, WhiteSet=0;
-
- int rgb[3], red, grn, blu;
- int *which, tindex, best = 1000*3, psize = PaletteSize/3;
-
- float max_value = (float)gx_max_color_value;
-
- if (TrueColor) {
- tindex = psize;
- }
- else {
- tindex = ColorIndex;
- }
-
- if (ColorBits == 1) { /* monochrome */
- return ((r | g | b) > gx_max_color_value / 2 ?
- (gx_color_index)0 : (gx_color_index)1);
- }
-
- /* Change GS rgb values to ST vdi rgb values. */
-
- red = rgb[0] = 1000 * ((float)r / max_value);
- grn = rgb[1] = 1000 * ((float)g / max_value);
- blu = rgb[2] = 1000 * ((float)b / max_value);
-
- switch (red + grn + blu) {
-
- case WT: /* white -- keep at vdi index 0 */
- if (!TrueColor) {
- if (!WhiteSet) {
- Palette[0] = rgb[0];
- Palette[1] = rgb[1];
- Palette[2] = rgb[2];
- vs_color(VdiHandle, 0, rgb);
- WhiteSet = 1;
- }
- return (gx_color_index)ColorReg[0];
- }
-
- case BK: /* black -- keep at vdi index 1 */
- if (!TrueColor) {
- if (!BlackSet) {
- Palette[3] = rgb[0];
- Palette[4] = rgb[1];
- Palette[5] = rgb[2];
- vs_color(VdiHandle, 1, rgb);
- BlackSet = 1;
- }
- return (gx_color_index)ColorReg[1];
- }
-
- default: /* search the palette for the requested color */
- while ( tindex-- > 0 ) {
- diff = *pptr - red;
- if ( diff < 0 ) diff = -diff;
-
- if ( diff < best ) { /* quick rejection */
- int dg = pptr[1] - grn;
- if ( dg < 0 ) dg = -dg;
-
- if ( (diff += dg) < best ) { /* quick rejection */
- int db = pptr[2] - blu;
- if ( db < 0 ) db = -db;
-
- if ( (diff += db) < best )
- which = pptr, best = diff;
- if (best == 0) break;
- }
-
- }
- pptr += 3;
- }
-
- /* If a color register is available, set it,
- * if not, return the nearest color match.
- */
-
- if (best == 0 || ColorIndex >= psize || TrueColor) {
- return (gx_color_index)ColorReg[(which - Palette)/3];
- }
- else {
- int i;
-
- if (ColorIndex == 3 && ColorBits > 2) ColorIndex++;
- i = 3 * ColorIndex;
-
- Palette[i] = rgb[0];
- Palette[i+1] = rgb[1];
- Palette[i+2] = rgb[2];
-
- vs_color(VdiHandle, ColorIndex, rgb);
-
- return (gx_color_index)ColorReg[ColorIndex++];
- }
-
- break;
-
- }
- }
-
- /* Map a color index to a r-g-b color. */
- int
- stvdi_map_color_rgb(gx_device *pdev, gx_color_index color,
- gx_color_value prgb[3])
- {
- int *pptr;
- int max_value = gx_max_color_value;
-
- if (ColorBits == 1) { /* monochrome */
- return gdev_prn_map_color_rgb(pdev, color, prgb);
- }
-
- pptr = Palette + (int)color * 3;
-
- prgb[0] = (pptr[0] * max_value) / 1000;
- prgb[1] = (pptr[1] * max_value) / 1000;
- prgb[2] = (pptr[2] * max_value) / 1000;
-
- return 0;
- }
-
- /* Copy an image from Ghostscript's format to standard color planes. */
-
- int
- stvdi_pack_to_plane(void)
- {
- int i, plane_size;
-
- words = height * word_width - 1; /* pixels/16 - 1 */
- plane_size = 2 * word_width * height;
-
- /* Plane[i] holds the address of the ith color plane. */
-
- for (i=0; i<ColorBits; i++) {
- plane[i] = (ushort *)(cbase + i * plane_size);
- }
-
- /* Jump to the appropriate assembler image transformation. */
-
- switch (ColorBits) {
-
- case 2: /* Two bit color. */
- trans_2();
- break;
-
- case 4: /* Four bit color. */
- trans_4();
- break;
-
- case 8: /* Eight bit color. */
- trans_8();
- break;
-
- case 16: /* 16-bit color. */
- trans_16();
- break;
-
- }
-
- return (0);
- }
-
- /* This routine is necessary because the vdi color indices are not
- * the same as the color register numbers used by the hardware.
- * It figures out the color register number associated with each
- * color index by writing each color index to the screen and then
- * examining which color register was used.
- */
-
- int reg_to_index(int *index_array, int c_bits, int p_size)
- {
- unsigned short *wp;
-
- int i, index, creg, xy_pos[2], xy_size[8];
-
- long tpixel[8], plane[8];
-
- MFDB temp, screen, planes;
-
- screen.fd_addr = (long)NULL;
-
- /* Temporary storage for for 16 screen pixels. */
-
- temp.fd_addr = (long)tpixel;
- temp.fd_w = 16;
- temp.fd_h = 1;
- temp.fd_wdwidth = 1;
- temp.fd_stand = 0;
- temp.fd_nplanes = c_bits;
-
- /* 16 screen pixels in plane format. */
-
- planes.fd_addr = (long)plane;
- planes.fd_w = 16;
- planes.fd_h = 1;
- planes.fd_wdwidth = 1;
- planes.fd_stand = 0;
- planes.fd_nplanes = c_bits;
-
- /* Screen position to write pixel. */
-
- xy_pos[0] = 0;
- xy_pos[1] = 0;
-
- /* Size of screen image to copy. */
-
- xy_size[0] = 0;
- xy_size[1] = 0;
- xy_size[2] = 15;
- xy_size[3] = 0;
- xy_size[4] = xy_size[0];
- xy_size[5] = xy_size[1];
- xy_size[6] = xy_size[2];
- xy_size[7] = xy_size[3];
-
- vswr_mode(VdiHandle, 1); /* overwrite mode */
- vsm_type(VdiHandle, 1); /* marker type "dot" */
-
- for (index=0; p_size--; index++) {
- wp = (short int *)plane;
-
- vsm_color(VdiHandle, index); /* set pixel color */
- v_pmarker(VdiHandle, 1, xy_pos); /* write pixel to screen */
-
- /* Copy pixel into temporary storage (transforming directly
- * from the screen doesn't work on my machine).
- */
-
- vro_cpyfm(VdiHandle, 3, xy_size, &screen, &temp);
-
- /* Transform the screen image into color plane format. */
-
- vr_trnfm(VdiHandle, &temp, &planes);
-
- /* Convert the color plane information into a register number. */
-
- creg = 0;
-
- for (i=1; i<=c_bits; wp++, i++) {
- if (*wp & 0x8000) {
- creg += (1 << (i-1));
- }
- }
-
- /* index_array[creg] = index; */
- index_array[index] = creg;
-
- }
-
- }
-
- __asm__("
-
- .globl _trans_2, _trans_4, _trans_8, _trans_16
-
- _trans_2:
-
- | a0 address of plane 0
- | a1 address of plane 1
- | a4 address of source pixels
- | d7 #pixels/16 - 1
-
- moveml a0-a5/d0-d7, sp@- | save the registers
-
- movel _plane, a0
- movel _plane+4, a1
- movel _tbase, a4
- movel _words, d7
-
- next_block2:
- moveq #1, d6 | 2 words for 16 pixels
-
- next_word2:
- movew a4@+, d4 | get 8 pixels
- moveq #7, d5 | 8 pixels/word
-
- next_pixel2:
- addw d4, d4 | scatter pixels to 2 planes
- addxw d0, d0
- addw d4, d4
- addxw d1, d1
-
- dbra d5, next_pixel2
-
- dbra d6, next_word2
-
- movew d0, a1@+ | store 1 word of each bit plane
- movew d1, a0@+
-
- subql #1, d7
- bpl next_block2
-
- moveml sp@+, a0-a5/d0-d7 | restore the registers
- rts
-
-
- _trans_4:
-
- | a0 address of plane 0
- | a1 address of plane 1
- | a2 address of plane 2
- | a3 address of plane 3
- | a4 address of source pixels
- | d7 #pixels/16 - 1
-
- moveml d0-d7/a0-a5, sp@- | save registers
-
- movel _plane, a0
- movel _plane+4, a1
- movel _plane+8, a2
- movel _plane+12, a3
- movel _tbase, a4
- movel _words, d7
-
- next_block4:
- moveq #3,d6 | 4 words for 16 pixels
-
- next_word4:
- movew a4@+,d4 | get 4 pixels
- moveq #3,d5 | 4 pixels/word
-
- next_pixel4:
- addw d4,d4 | scatter pixels to four planes
- addxw d0,d0
- addw d4,d4
- addxw d1,d1
- addw d4,d4
- addxw d2,d2
- addw d4,d4
- addxw d3,d3
-
- dbra d5,next_pixel4
-
- dbra d6,next_word4
-
- movew d0,a3@+ | store 1 word of each bit plane
- movew d1,a2@+
- movew d2,a1@+
- movew d3,a0@+
-
- subql #1,d7
- bpl next_block4
-
- moveml sp@+, d0-d7/a0-a5 | restore registers
- rts
-
- _trans_8:
-
- | a0 address of planes 0 & 4
- | a1 address of planes 1 & 5
- | a2 address of planes 2 & 6
- | a3 address of planes 3 & 7
- | a4 address of source pixels
- | a5 pointer to array containing addresses of color planes
- | d7 #pixels/16 - 1
-
- moveml d0-d7/a0-a5, sp@- | save registers
-
- movel _tbase, a4
- movel #_plane, a5
- movel _words, d7
-
- pass_one8: | first pass through the image
- moveml a5@(16), a0-a3 | get addresses of second 4 planes
-
- next_block8:
- moveq #7, d6 | 8 words for 16 pixels
-
- next_word8:
- movew a4@+, d4 | get 2 pixels
-
- addw d4, d4 | scatter to first 4 planes
- addxw d0, d0
- addw d4, d4
- addxw d1, d1
- addw d4, d4
- addxw d2, d2
- addw d4, d4
- addxw d3, d3
- rolw #4, d4
- addw d4, d4
- addxw d0, d0
- addw d4, d4
- addxw d1, d1
- addw d4, d4
- addxw d2, d2
- addw d4, d4
- addxw d3, d3
-
- dbra d6, next_word8
-
- movew d0, a3@+ | store 1 word of each bit plane
- movew d1, a2@+
- movew d2, a1@+
- movew d3, a0@+
-
- subql #1, d7
- bpl next_block8
-
- pass_two8: | second pass through the image
- moveml a5@, a0-a3 | get addresses of first 4 planes
- movel _words, d7 | get #pixels/16 - 1
- movel _tbase, a4 | get address of source pixels
-
- next_block8_2:
- moveq #7, d6 | 8 words for 16 pixels
-
- next_word8_2:
- movew a4@+, d4 | get 2 pixels
- rolw #4, d4
-
- addw d4, d4 | scatter to last 4 planes
- addxw d0, d0
- addw d4, d4
- addxw d1, d1
- addw d4, d4
- addxw d2, d2
- addw d4, d4
- addxw d3, d3
- rolw #4, d4
- addw d4, d4
- addxw d0, d0
- addw d4, d4
- addxw d1, d1
- addw d4, d4
- addxw d2, d2
- addw d4, d4
- addxw d3, d3
-
- dbra d6, next_word8_2
-
- movew d0, a3@+ | store 1 word of each bit plane
- movew d1, a2@+
- movew d2, a1@+
- movew d3, a0@+
-
- subql #1,d7
- bpl next_block8_2
-
- moveml sp@+, d0-d7/a0-a5 | restore registers
- rts
-
-
- _trans_16:
-
- | a0 address of planes 0, 4, 8, & 12
- | a1 address of planes 1, 5, 9, & 13
- | a2 address of planes 2, 6, 10, & 14
- | a3 address of planes 3, 7, 11, & 15
- | a4 address of source pixels
- | a5 pointer to array containing addresses of color planes
- | d7 #pixels/16 - 1
-
- moveml d0-d7/a0-a5, sp@- | save registers
-
- movel _tbase, a4
- movel #_plane, a5
- movel _words, d7
-
- pass_one16: | first pass through the image
- moveml a5@(48), a0-a3 | get addresses of last 4 planes
-
- next_block16:
- moveq #15, d6 | 16 words for 16 pixels
-
- next_word16:
- movew a4@+, d4 | get 1 pixel
-
- addw d4, d4 | scatter to first 4 planes
- addxw d0, d0
- addw d4, d4
- addxw d1, d1
- addw d4, d4
- addxw d2, d2
- addw d4, d4
- addxw d3, d3
-
- dbra d6, next_word16
-
- movew d0, a3@+ | store 1 word of each bit plane
- movew d1, a2@+
- movew d2, a1@+
- movew d3, a0@+
-
- subql #1, d7
- bpl next_block16
-
- pass_two16: | second pass through the image
- moveml a5@(32), a0-a3 | get addresses of next 4 planes
- movel _words, d7 | get #pixels/16 - 1
- movel _tbase, a4 | get address of source pixels
-
- next_block16_2:
- moveq #15, d6 | 16 words for 16 pixels
-
- next_word16_2:
- movew a4@+, d4 | get 1 pixel
- rolw #4, d4
-
- addw d4, d4 | scatter to last 4 planes
- addxw d0, d0
- addw d4, d4
- addxw d1, d1
- addw d4, d4
- addxw d2, d2
- addw d4, d4
- addxw d3, d3
-
- dbra d6, next_word16_2
-
- movew d0, a3@+ | store 1 word of each bit plane
- movew d1, a2@+
- movew d2, a1@+
- movew d3, a0@+
-
- subql #1,d7
- bpl next_block16_2
-
- pass_three16: | third pass through the image
- moveml a5@(16), a0-a3 | get addresses of next 4 planes
- movel _words, d7 | get #pixels/16 - 1
- movel _tbase, a4 | get address of source pixels
-
- next_block16_3:
- moveq #15, d6 | 16 words for 16 pixels
-
- next_word16_3:
- movew a4@+, d4 | get 1 pixel
- rolw #8, d4
-
- addw d4, d4 | scatter to last 4 planes
- addxw d0, d0
- addw d4, d4
- addxw d1, d1
- addw d4, d4
- addxw d2, d2
- addw d4, d4
- addxw d3, d3
-
- dbra d6, next_word16_3
-
- movew d0, a3@+ | store 1 word of each bit plane
- movew d1, a2@+
- movew d2, a1@+
- movew d3, a0@+
-
- subql #1,d7
- bpl next_block16_3
-
- pass_four16: | fourth pass through the image
- moveml a5@, a0-a3 | get addresses of first 4 planes
- movel _words, d7 | get #pixels/16 - 1
- movel _tbase, a4 | get address of source pixels
-
- next_block16_4:
- moveq #15, d6 | 16 words for 16 pixels
-
- next_word16_4:
- movew a4@+, d4 | get 1 pixel
- rorw #4, d4
-
- addw d4, d4 | scatter to last 4 planes
- addxw d0, d0
- addw d4, d4
- addxw d1, d1
- addw d4, d4
- addxw d2, d2
- addw d4, d4
- addxw d3, d3
-
- dbra d6, next_word16_4
-
- movew d0, a3@+ | store 1 word of each bit plane
- movew d1, a2@+
- movew d2, a1@+
- movew d3, a0@+
-
- subql #1,d7
- bpl next_block16_4
-
- moveml sp@+, d0-d7/a0-a5 | restore registers
- rts
-
- ");
-